﻿using System.Collections;
using System.Collections.Generic;
using Entitas;
using Entitas.Unity;
using Game.Data;
using UnityEngine;

namespace Game
{
    /// <summary>
    /// 视图层基类
    /// </summary>
    public class ViewBase : MonoBehaviour, IView, IGameDestoryItemListener
    {
        protected GameEntity gameEntity;

        public virtual void Link(IEntity entity, IContext context)
        {
            if (entity is GameEntity)
            {
                gameEntity = entity as GameEntity;

            }
            else
            {
                Debug.Log("类型转换出错！！！");
                return;
            }
            gameObject.Link(gameEntity);
            gameEntity.AddGameDestoryItemListener(this);
        }

        public virtual void OnGameDestoryItem(GameEntity entity)
        {
            //解绑 
            gameObject.Unlink();
        }


    }
}

